<?php
/**
 * 同时请求5个url
 */
$urls = [
    'http://baidu.com',
    'http://baidu.com/s?wd=python',
    'http://baidu.com/s?wd=python',
    'http://baidu.com/s?wd=python',
    'http://baidu.com/s?wd=java'
];
$workers = [];
echo ">>>" . date('H:i:s'). PHP_EOL;
for ($i=0; $i <5 ; $i++) { 
    $process = new Swoole\Process(function ($worker) use($urls, $i){
        $res = getContent($urls[$i]);
        file_put_contents(__DIR__ . '/temp/' . $i, $res);
        $worker->write("$urls[$i] -> Suss");
    }, true);
    $pid = $process->start();
    $workers[$pid] = $process;
}

foreach ($workers as $process) {
    echo $process->read() . PHP_EOL;
}
echo "<<<" . date('H:i:s'). PHP_EOL;

function getContent($url){
    return file_get_contents($url);
}
